﻿// Copyright (c)  MOKEYISH. All rights reserved.
// Licensed under the MIT License, See License.txt in the project root for license information.

using System.Collections.Generic;

namespace NSQL.Expressions
{
    public class MatchPair<TWhen, TThen>
    {
        public TWhen When { get; set; }
        public TThen Then { get; set; }
    }

    public class SimpleMatchExpression : BaseExpression, ISimpleMatchExpression
    {
        public IValueExpression Value { get; set; }

        public IList<MatchPair<IValueExpression, IValueExpression>> Matches { get; } =
            new List<MatchPair<IValueExpression, IValueExpression>>();

        public IValueExpression Default { get; set; }

        public SimpleMatchExpression()
        {
        }

        public SimpleMatchExpression(IValueExpression expression,
            IEnumerable<MatchPair<IValueExpression, IValueExpression>> matches, IValueExpression @default)
        {
            Value = expression;
            foreach (var match in matches)
            {
                Matches.Add(match);
            }

            Default = @default;
        }

        public override T Accept<T>(IExpressionVisitor<T> visitor) => visitor.Visit(this);
    }
}